package com.example.demo.Controller;

import com.example.demo.dao.ChatJpa;
import com.example.demo.dao.IndexJpa;
import com.example.demo.dao.MyInfoJpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class MyInfo {
    @Autowired
    MyInfoJpa myInfoJpa;
    @Autowired
    IndexJpa indexJpa;

//查询用户名
@RequestMapping("/getNickName")
public String getNickName(String yb_userid) {
    String name="";
    //status:状态码，100正常，200表示无该用户，300表示一个id对应多个用户
    String status="";
    //查看该用户是否存在(0不存在,1存在)
    int is_exist= myInfoJpa.userIsExist(yb_userid);
    System.out.println("is_exist="+is_exist);
    if(is_exist==0)
    {
        status="200";
        return status;
    }
    else if(is_exist==1)
    {
        status="100";
        name= myInfoJpa.getNickName(yb_userid);
        return name;
    }
    else
    {
        status="300";
        return status;
    }
}

//修改用户名
@RequestMapping("/changeNickName")
public void changeNickName(String yb_userid,String name)
{
    myInfoJpa.setNickName(yb_userid,name);
}

//查看自己发布的活动
@RequestMapping("/activity/getMineActivity")
public ArrayList getMineActivity(String userid)
{
    ArrayList my_act=new ArrayList();
    my_act=myInfoJpa.getMineActivity(userid);
    return my_act;
}

//删除自己发布的活动(返回100表示正常删除,200表示错误)
    @RequestMapping("/activity/deleteMineActivity")
public ArrayList deleteMineActivity(String actid,String userid,String category)
{
    //status:状态码,100正常删除,200删除异常;check:查询是否正常删除的数组，正常删除大小为0
    int status=100;
    myInfoJpa.deleteMineActivity(actid,userid);
    indexJpa.reduceNum(category);
    ArrayList a=new ArrayList();
    a=myInfoJpa.getMineActivity(userid);
    return a;

}

//查询自己发布的活动信息
@RequestMapping("/activity/getActivityInfo")
public ArrayList getActivityInfo(String actid,String userid) {
    ArrayList actlist=new ArrayList();
    actlist= myInfoJpa.getActivityInfo(actid,userid);
    return actlist;
}

//查看我关注的活动
@RequestMapping("/favourite/getMyFavourite")
public ArrayList getMyFavourite(String userid) {
    ArrayList myfav=new ArrayList();
    myfav=myInfoJpa.getMyFavourite(userid);
    return myfav;
}

//取消关注
@RequestMapping("/favourite/deleteMyFavourite")
public void deleteMyFavourite(String actid,String userid) {
    myInfoJpa.deleteMyFavourite(actid,userid);
}

}
